Improve types on AssetIssuance struct#289
Conversation
Somehow I neglected to do this in ElementsProject#278
…nonce Previously we had been using the secp265k1_zkp::Tweak type to represent a blinding nonce in an issuance. This had a number of issues: * `Tweak` is a low-level crypto type which is ambiguous about whether or not it's secret or public, and doesn't have any meaning beyond "value you can add to a secp point" * In particular the special `ZERO_TWEAK` constant was interpreted to mean "new issuance" and this was implicit throughout the codebase. * As a foreign type, we could not directly implement any encoding or decoding traits on this; we had to convert it to/from a byte array. * As a "general" type, it doesn't distinguish between various uses of tweak, which can lead to dangerous type confusion. * `Tweak` cannot represent values that are out of range of the secp256k1 group, while technically Elements permits such transactions to exist (e.g. `decoderawtransaction` will accept them), even though it will fail VerifyAmounts. (I carefully checked all the codepaths: if the amounts in an issuance are null, so much be the nonce (or else you get a "superfluous issuance" error; if they're non-null and the blinding nonce is zero (which is in-range), it's a new issuance; if it's not zero then it's put into secp256k1_generator_generate_blinded which checks for overflow as its very first check.)
The only place this is actually "consensus encoded" is arguably in the pegin witness stack, but that's reason enough to have these.
|
I think after this we should cut a 0.27 release of rust-elements. I have a bunch of breakage related to encoding coming down the pike and it'd be good to have a release right before and after that to try to contain the damage for people updating their stuff. |
There was a problem hiding this comment.
Changes look good and principled. Tests pass locally, ACK 02122be.
Some minor editorial comments.
| @@ -1,4 +1,4 @@ | |||
| // Rust Elements Library | |||
| // Rust Elements Libraryss | |||
There was a problem hiding this comment.
typo
| // Rust Elements Libraryss | |
| // Rust Elements Librarys |
| } | ||
|
|
||
| encoding::encoder_newtype_exact! { | ||
| /// Encoder for the [`OutPoint`] type. |
There was a problem hiding this comment.
| /// Encoder for the [`OutPoint`] type. | |
| /// Encoder for the [`AssetEntropy`] type. |
| } | ||
|
|
||
| encoding::encoder_newtype_exact! { | ||
| /// Encoder for the [`OutPoint`] type. |
There was a problem hiding this comment.
| /// Encoder for the [`OutPoint`] type. | |
| /// Encoder for the [`AssetBlindingNonce`] type. |
| } | ||
|
|
||
| encoding::encoder_newtype_exact! { | ||
| /// Encoder for the [`OutPoint`] type. |
There was a problem hiding this comment.
| /// Encoder for the [`OutPoint`] type. | |
| /// Encoder for the [`AssetId`] type. |
|
|
||
| use crate::{encode::serialize, pset::PartiallySignedTransaction}; | ||
| use crate::issuance::AssetBlindingNonce; | ||
| use crate::{encode::serialize, pset::PartiallySignedTransaction}; |
There was a problem hiding this comment.
| use crate::{encode::serialize, pset::PartiallySignedTransaction}; | |
| use crate::{encode::serialize, pset::PartiallySignedTransaction}; |
indenting
| /// used to blind the reissuance token (which must be blinded in order to be | ||
| /// spent, due to a quirk in the Elements consensus code.) | ||
| /// | ||
| /// Conceputally this can be thought of as an `Option<AssetBlindingFactor>`, except |
There was a problem hiding this comment.
| /// Conceputally this can be thought of as an `Option<AssetBlindingFactor>`, except | |
| /// Conceptually this can be thought of as an `Option<AssetBlindingFactor>`, except |
| use std::str::FromStr; | ||
|
|
||
| use crate::{encode::serialize, pset::PartiallySignedTransaction}; | ||
| use crate::issuance::AssetBlindingNonce; |
There was a problem hiding this comment.
nit: unnecessary since super::* is imported below
| /// This is something of a dangerous function, since in general blinding factors should | ||
| /// be considered secret data, while blinding nonces are public (they are encoded on | ||
| /// the blockchain). So callers of this function should be sure that this is a blinding | ||
| /// factor that they intend to reveal.) |
There was a problem hiding this comment.
| /// factor that they intend to reveal.) | |
| /// factor that they intend to reveal. |
Use strong types for asset entropy and blinding nonce.